<?php

namespace app\admin\model;

use think\Model;


class Homepage extends Model
{

    

    

    // 表名
    protected $name = 'homepage';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text',
        'is_vip_text'
    ];
    

    
    public function getTypeList()
    {
//        '3' => __('Type 3'),
        return ['1' => __('Type 1'), '2' => __('Type 2'),  '4' => __('Type 4'), '5' => __('Type 5')];
    }

    public function getIsVipList()
    {
        return ['1' => __('Is_vip 1'), '2' => __('Is_vip 2')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsVipTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_vip']) ? $data['is_vip'] : '');
        $list = $this->getIsVipList();
        return isset($list[$value]) ? $list[$value] : '';
    }
public function getImageAttr($value, $data)
{
    $value = $value ? $value : (isset($data['image']) ? $data['image'] : '');
    return $value ? cdnurl($value, true) : '';
}


public function textBooks()
{
    return $this->belongsTo(TextBooks::class, 'path', 'id', [], 'LEFT')->setEagerlyType(0);
}

}
